package com.egoo.ticket.server.config.swagger;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * @author Administrator
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
@ConditionalOnProperty(prefix = "eeip.eeif.swagger", name = "enable", havingValue = "true")
public class Swagger2Config {

	@Bean
	public Docket ewsApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.groupName("智能工单系统")
				.genericModelSubstitutes(DeferredResult.class)
				.useDefaultResponseMessages(false)
				.forCodeGeneration(true)
				.pathMapping("/").select()
				.paths(regex("/v1/.*"))
				.build()
				.apiInfo(ddtApiInfo());
	}

	private ApiInfo ddtApiInfo() {
		return new ApiInfoBuilder()
				.title("智能工单系统")
				.version("3.2.2.2")
				.build();
	}
}